<?php

namespace app\admin\controller;
use think\db\Query;
use think\Controller;
class Order extends Controller
{
	public function orderList(){
		
		
		if(request()->isAjax()){
			$sql = "SELECT o.id,o.userName,o.mobile,o.age,o.userHousehold,o.time,o.order_sn,o.order_status,o.aptitude,u.user_name,u.real_name,o.results FROM  snake_order as o left join  snake_user as u on  o.salemanid=u.id where o.state = 0 and o.vip_judgement = 0 order by o.aptitude,o.id desc";
			$orderList = db("order") ->query($sql);
			
            //$orderList = db("order")->alias('o')->join('user u','o.salemanid = u.id')->where('o.state = 0')->field('o.id,o.userName,o.mobile,o.age,o.userHousehold,o.time,o.order_sn,o.order_status,o.aptitude,u.user_name')->order('o.aptitude ,o.id desc')->select();
			if($orderList){
			 return json($orderList);
			}
		}else{
		// 渲染模板输出
		return $this->fetch();
		}
	}
	//查看详情页面
	public function orderinfo(){
		//if(request()->isPost()){
		if(request()->isGet()){
			$data = input('get.id');
			// 产品详情
			$orderinfo = db('order')->where("id = {$data} ")->find();
			
			//详情处理
			if($orderinfo['job'] == 1 ){
				$orderinfo['job'] = '生意';
			}elseif ($orderinfo['job'] ==2 ) {
				$orderinfo['job'] = '上班';
			}elseif ($orderinfo['job'] ==0) {
				$orderinfo['job'] = '';
			}
			//人寿
			if($orderinfo['isInsurance'] == 1 ){
				$orderinfo['isInsurance'] = '有';
			}elseif ($orderinfo['isInsurance'] ) {
				$orderinfo['isInsurance'] = '没有';
			}
			//小车
			if($orderinfo['isCar'] == 1 ){
				$orderinfo['isCar'] = '有';
			}elseif ($orderinfo['isCar'] ) {
				$orderinfo['isCar'] = '没有';
			}

			//房产
			if($orderinfo['isHouse'] == 1 ){
				$orderinfo['isHouse'] = '有';
			}elseif ($orderinfo['isHouse'] ) {
				$orderinfo['isHouse'] = '没有';
			}
			//贷款
			if($orderinfo['isRepayLoan'] == 1 ){
				$orderinfo['isRepayLoan'] = '有';
			}elseif ($orderinfo['isRepayLoan'] ) {
				$orderinfo['isRepayLoan'] = '没有';
			}
			//征信
			if($orderinfo['isCheckCredit'] == 1 ){
				$orderinfo['isCheckCredit'] = '是';
			}elseif ($orderinfo['isCheckCredit'] ) {
				$orderinfo['isCheckCredit'] = '否';
			}
			//信用卡 isCreditCard

			if($orderinfo['isCreditCard'] == 1 ){
				$orderinfo['isCreditCard'] = '有';
			}elseif ($orderinfo['isCreditCard'] ) {
				$orderinfo['isCreditCard'] = '否';
			}
			//var_dump($orderinfo['isCreditCard']);die();
			//转化数字
			if($orderinfo['sex'] ==1){
				$orderinfo['sex'] = '男';
			}elseif ($orderinfo['sex'] ==2) {
				$orderinfo['sex'] = '女';
			}


			if($orderinfo['degree'] == 0 and $orderinfo['degree'] != ''){
				$orderinfo['degree'] = '本科';
			}elseif ($orderinfo['degree']== 1 ) {
				$orderinfo['degree'] = '大专';
			}elseif ($orderinfo['degree']== 2 ) {
				$orderinfo['degree'] = '高中';
			}elseif ($orderinfo['degree']== 3 ) {
				$orderinfo['degree'] = '初中及以下';
			}




			if($orderinfo['isMarry'] ==1){
				$orderinfo['isMarry'] = '是';
			}elseif ($orderinfo['isMarry']) {
				$orderinfo['isMarry'] = '否';
			}

			if($orderinfo['isLicense'] == 1 ){
				$orderinfo['isLicense'] = '是';
			}elseif ($orderinfo['isLicense'] ) {
				$orderinfo['isLicense'] = '否';
			}
			  
			if($orderinfo['license'] == 0 and $orderinfo['license'] != ''){
				$orderinfo['license'] = '1-2月';
			}elseif ($orderinfo['license']== 1 ) {
				$orderinfo['license'] = '3-5月';
			}elseif ($orderinfo['license']== 2 ) {
				$orderinfo['license'] = '6-11月';
			}elseif ($orderinfo['license']== 3 ) {
				$orderinfo['license'] = '1-2年';
			}elseif ($orderinfo['license']== 4 ) {
				$orderinfo['license'] = '2年以上';
			}

			if($orderinfo['bankFlow'] == 0 and $orderinfo['bankFlow'] != ''){
				$orderinfo['bankFlow'] = '30万以下';
			}elseif ($orderinfo['bankFlow']== 1 ) {
				$orderinfo['bankFlow'] = '30-100万';
			}elseif ($orderinfo['bankFlow']== 2 ) {
				$orderinfo['bankFlow'] = '100-300万';
			}elseif ($orderinfo['bankFlow']== 3 ) {
				$orderinfo['bankFlow'] = '300万以上';
			}

			if($orderinfo['invoiceAmount'] == 0 and $orderinfo['invoiceAmount'] != ''){
				$orderinfo['invoiceAmount'] = '100万以下';
			}elseif ($orderinfo['invoiceAmount']== 1 ) {
				$orderinfo['invoiceAmount'] = '100-300万';
			}elseif ($orderinfo['invoiceAmount']== 2 ) {
				$orderinfo['invoiceAmount'] = '300-500万';
			}elseif ($orderinfo['invoiceAmount']== 3 ) {
				$orderinfo['invoiceAmount'] = '500-1000万';
			}elseif ($orderinfo['invoiceAmount']== 4 ) {
				$orderinfo['invoiceAmount'] = '1000万以上';
			}

			if($orderinfo['isSecurity1'] == 1){
				$orderinfo['isSecurity1'] = '是';
			}elseif ($orderinfo['isSecurity1'] ) {
				$orderinfo['isSecurity1'] = '否';
			}

			if($orderinfo['security1'] == 0 and $orderinfo['security1'] != ''){
				$orderinfo['security1'] = '6个月内';
			}elseif ($orderinfo['security1']== 1 ) {
				$orderinfo['security1'] = '1年内';
			}elseif ($orderinfo['security1']== 2 ) {
				$orderinfo['security1'] = '1-2年内';
			}elseif ($orderinfo['security1']== 3 ) {
				$orderinfo['security1'] = '2年以上';
			}

			if($orderinfo['isPublicFunds1'] == 1){
				$orderinfo['isPublicFunds1'] = '是';
			}elseif ($orderinfo['isPublicFunds1'] ) {
				$orderinfo['isPublicFunds1'] = '否';
			}

			if($orderinfo['publickFunds1'] == 0 and $orderinfo['publickFunds1'] != ''){
				$orderinfo['publickFunds1'] = '6个月内';
			}elseif ($orderinfo['publickFunds1']== 1 ) {
				$orderinfo['publickFunds1'] = '1年内';
			}elseif ($orderinfo['publickFunds1']== 2 ) {
				$orderinfo['publickFunds1'] = '1-2年内';
			}elseif ($orderinfo['publickFunds1']== 3 ) {
				$orderinfo['publickFunds1'] = '2年以上';
			}
			

			if($orderinfo['Salary'] == 0 and $orderinfo['Salary'] != ''){
				$orderinfo['Salary'] = '打卡';
			}elseif ($orderinfo['Salary']== 1 ) {
				$orderinfo['Salary'] = '现金';
			}elseif ($orderinfo['Salary']== 2 ) {
				$orderinfo['Salary'] = '打卡、现金都有';
			}

			if($orderinfo['bankFlow2'] == 0 and $orderinfo['bankFlow2'] != ''){
				$orderinfo['bankFlow2'] = '3千以下';
			}elseif ($orderinfo['bankFlow2']== 1 ) {
				$orderinfo['bankFlow2'] = '3-5千';
			}elseif ($orderinfo['bankFlow2']== 2 ) {
				$orderinfo['bankFlow2'] = '5千-1万';
			}elseif ($orderinfo['bankFlow2']== 3 ) {
				$orderinfo['bankFlow2'] = '1万以上';
			}

			if($orderinfo['isSecurity2'] == 1){
				$orderinfo['isSecurity2'] = '是';
			}elseif ($orderinfo['isSecurity2'] ) {
				$orderinfo['isSecurity2'] = '否';
			}


			if($orderinfo['security2'] == 0  and $orderinfo['security2'] != ''){
				$orderinfo['security2'] = '6个月内';
			}elseif ($orderinfo['security2']== 1 ) {
				$orderinfo['security2'] = '1年内';
			}elseif ($orderinfo['security2']== 2 ) {
				$orderinfo['security2'] = '1-2年内';
			}elseif ($orderinfo['security2']== 3 ) {
				$orderinfo['security2'] = '2年以上';
			}

			
			if($orderinfo['isPublicFunds2'] == 1){
				$orderinfo['isPublicFunds2'] = '是';
			}elseif ($orderinfo['isPublicFunds2'] ) {
				$orderinfo['isPublicFunds2'] = '否';
			}

			if($orderinfo['publickFunds2'] == 0 and $orderinfo['publickFunds2'] != ''){
				$orderinfo['publickFunds2'] = '6个月内';
			}elseif ($orderinfo['publickFunds2']== 1 ) {
				$orderinfo['publickFunds2'] = '1年内';
			}elseif ($orderinfo['publickFunds2']== 2 ) {
				$orderinfo['publickFunds2'] = '1-2年内';
			}elseif ($orderinfo['publickFunds2']== 3 ) {
				$orderinfo['publickFunds2'] = '2年以上';
			}

			// //5
			// if($orderinfo['isCreditCard'] == 1){
			// 	$orderinfo['isCreditCard'] = '是';
			// }elseif ($orderinfo['isCreditCard'] ) {
			// 	$orderinfo['isCreditCard'] = '否';
			//}

			if($orderinfo['CreditCardNumber'] == 0){
				$orderinfo['CreditCardNumber'] = '1-3张';
			}elseif ($orderinfo['CreditCardNumber']== 1 ) {
				$orderinfo['CreditCardNumber'] = '3-5张';
			}elseif ($orderinfo['CreditCardNumber']== 2 ) {
				$orderinfo['CreditCardNumber'] = '5-10张';
			}elseif ($orderinfo['CreditCardNumber']== 3 ) {
				$orderinfo['CreditCardNumber'] = '10张以上';
			}



			if($orderinfo['isCreditCardNormal'] == 0 and $orderinfo['isCreditCardNormal'] != ''){
				$orderinfo['isCreditCardNormal'] = '正常';
			}elseif ($orderinfo['isCreditCardNormal']== 1 ) {
				$orderinfo['isCreditCardNormal'] = '偶尔逾期';
			}elseif ($orderinfo['isCreditCardNormal']== 2 ) {
				$orderinfo['isCreditCardNormal'] = '经常逾期';
			}

			if($orderinfo['needToLoanTime'] == 0 and $orderinfo['needToLoanTime'] != ''){
				$orderinfo['needToLoanTime'] = '1年';
			}elseif ($orderinfo['needToLoanTime']== 1 ) {
				$orderinfo['needToLoanTime'] = '2年';
			}elseif ($orderinfo['needToLoanTime']== 2 ) {
				$orderinfo['needToLoanTime'] = '3年';
			}elseif ($orderinfo['needToLoanTime']== 3 ) {
				$orderinfo['needToLoanTime'] = '3年以上';
			}
				
		
			//var_dump($orderinfo['HouseAmount']);
			// $hello = explode(',',$orderinfo['CheckCreditMonth']);
			// foreach ($hello as $key => $value) {
			// 	$orderinfo['CheckCreditMonth'.($key+1)] = $value -1;
									
			// }
				
			// 	if($orderinfo['insuranceAmount'] == 0 and $orderinfo['insuranceAmount'] != ''){
			// 	$orderinfo['insuranceAmount'] = '1份';
			// }elseif ($orderinfo['insuranceAmount']== 1 ) {
			// 	$orderinfo['insuranceAmount'] = '2份';
			// }elseif ($orderinfo['insuranceAmount']== 2 ) {
			// 	$orderinfo['insuranceAmount'] = '3份';
			// }elseif ($orderinfo['insuranceAmount']== 3 ) {
			// 	$orderinfo['insuranceAmount'] = '4份';
			// }elseif ($orderinfo['insuranceAmount']== 4 ) {
			// 	$orderinfo['insuranceAmount'] = '5份';
			// }

			$orderinfo['CheckCreditMonth'] = $orderinfo['CheckCreditMonth'] +1;



			$orderinfo['CheckCreditYears'] = $orderinfo['CheckCreditYears'] +1;


			$hello = explode(',',$orderinfo['CompanyInsurance']);
			foreach ($hello as $key => $value) {
				$orderinfo['CompanyInsurance'.($key+1)] = $value;
				switch ($orderinfo['CompanyInsurance'.($key+1)]) {
					case '0':
						$orderinfo['CompanyInsurance'.($key+1)] = '其他';
						break;
						case '1':
						$orderinfo['CompanyInsurance'.($key+1)] = '平安保险';
						break;
						case '2':
						$orderinfo['CompanyInsurance'.($key+1)] = '中国人寿';
						break;
						case '3':
						$orderinfo['CompanyInsurance'.($key+1)] = '太平洋保险';
						break;
						case '4':
						$orderinfo['CompanyInsurance'.($key+1)] = '泰康保险';
						break;
						case '5':
						$orderinfo['CompanyInsurance'.($key+1)] = '新华保险';
						break;
						case '6':
						$orderinfo['CompanyInsurance'.($key+1)] = '中国人保';
						break;
						case '7':
						$orderinfo['CompanyInsurance'.($key+1)] = '阳光保险';
						break;
						case '8':
						$orderinfo['CompanyInsurance'.($key+1)] = '友邦保险';
						break;
						case '9':
						$orderinfo['CompanyInsurance'.($key+1)] = '中宏人寿';
						break;
						case '10':
						$orderinfo['CompanyInsurance'.($key+1)] = '中意人寿';
						break;
						case '11':
						$orderinfo['CompanyInsurance'.($key+1)] = '招商信诺';
						break;
						case '12':
						$orderinfo['CompanyInsurance'.($key+1)] = '太平人寿';
						break;
						case '13':
						$orderinfo['CompanyInsurance'.($key+1)] = '生命人寿（富德生命）';
						break;
						case '14':
						$orderinfo['CompanyInsurance'.($key+1)] = '工银安盛人寿';
						break;
						case '15':
						$orderinfo['CompanyInsurance'.($key+1)] = '中英人寿';
						break;
						case '16':
						$orderinfo['CompanyInsurance'.($key+1)] = '中美大都会';
						break;
						case '17':
						$orderinfo['CompanyInsurance'.($key+1)] = '信泰人寿';
						break;
						case '18':
						$orderinfo['CompanyInsurance'.($key+1)] = '中德安联';
						break;
						case '19':
						$orderinfo['CompanyInsurance'.($key+1)] = '建信人寿';
						break;
						case '20':
						$orderinfo['CompanyInsurance'.($key+1)] = '利安人寿';
						break;
						case '21':
						$orderinfo['CompanyInsurance'.($key+1)] = '陆家嘴人寿';
						break;
						case '22':
						$orderinfo['CompanyInsurance'.($key+1)] = '民生人寿';
						break;
						case '23':
						$orderinfo['CompanyInsurance'.($key+1)] = '农银人寿';
						break;
						case '24':
						$orderinfo['CompanyInsurance'.($key+1)] = '华泰人寿';
						break;
						case '25':
						$orderinfo['CompanyInsurance'.($key+1)] = '国华人寿';
						break;
						case '26':
						$orderinfo['CompanyInsurance'.($key+1)] = '合众人寿';
						break;
						case '27':
						$orderinfo['CompanyInsurance'.($key+1)] = '长城人寿';
						break;
						case '28':
						$orderinfo['CompanyInsurance'.($key+1)] = '华夏人寿';
						break;
						case '29':
						$orderinfo['CompanyInsurance'.($key+1)] = '光大永明人寿';
						break;
						case '30':
						$orderinfo['CompanyInsurance'.($key+1)] = '同方全球人寿';
						break;
						case '31':
						$orderinfo['CompanyInsurance'.($key+1)] = '恒安标准人寿';
						break;
						case '32':
						$orderinfo['CompanyInsurance'.($key+1)] = '恒大人寿';
						break;
						case '33':
						$orderinfo['CompanyInsurance'.($key+1)] = '东吴人寿';
						break;
						case '34':
						$orderinfo['CompanyInsurance'.($key+1)] = '幸福人寿';
						break;
						case '35':
						$orderinfo['CompanyInsurance'.($key+1)] = '中荷人寿';
						break;
						
					default:
						# code...
						break;
				}
			}

			unset($orderinfo['CompanyInsurance']) ;
			
			$hello = explode(',',$orderinfo['InsuranceType']);
			foreach ($hello as $key => $value) {
				$orderinfo['InsuranceType'.($key+1)] = $value;
					if($orderinfo['InsuranceType'.($key+1)] == 0 and $orderinfo['InsuranceType'.($key+1)] !=''){
					$orderinfo['InsuranceType'.($key+1)]= '保障型';
				}elseif ($orderinfo['InsuranceType'.($key+1)]== 1 ) {
					$orderinfo['InsuranceType'.($key+1)]= '分红型';
				}elseif ($orderinfo['InsuranceType'.($key+1)]== 2 ) {
					$orderinfo['InsuranceType'.($key+1)]= '万能型';
				}						
			}
			unset($orderinfo['InsuranceType']) ;

			$hello = explode(',',$orderinfo['insuranceBuyTime']);
			foreach ($hello as $key => $value) {
				$orderinfo['insuranceBuyTime'.($key+1)] = $value;
									
			}
			unset($orderinfo['insuranceBuyTime']) ;

			// $hello = explode(',',$orderinfo['insuranceBuyTime']);
			// foreach ($hello as $key => $value) {
			// 	$orderinfo['insuranceBuyTime'.($key+1)] = $value;
									
			// }
			// unset($orderinfo['insuranceBuyTime']) ;

			$hello = explode(',',$orderinfo['InsurancePayType']);
			foreach ($hello as $key => $value) {
				$orderinfo['InsurancePayType'.($key+1)] = $value;
					if($orderinfo['InsurancePayType'.($key+1)] == 0 and $orderinfo['InsurancePayType'.($key+1)] != ''){
					$orderinfo['InsurancePayType'.($key+1)]= '月缴';
				}elseif ($orderinfo['InsurancePayType'.($key+1)]== 1 ) {
					$orderinfo['InsurancePayType'.($key+1)]= '季缴';
				}elseif ($orderinfo['InsurancePayType'.($key+1)]== 2 ) {
					$orderinfo['InsurancePayType'.($key+1)]= '半年缴';
				}elseif ($orderinfo['InsurancePayType'.($key+1)]== 3 ) {
					$orderinfo['InsurancePayType'.($key+1)]= '年缴';
				}						
			}
			unset($orderinfo['InsurancePayType']) ;


			$hello = explode(',',$orderinfo['PremiumAmount']);
			foreach ($hello as $key => $value) {
				$orderinfo['PremiumAmount'.($key+1)] = $value;
									
			}
			unset($orderinfo['PremiumAmount']) ;

			$hello = explode(',',$orderinfo['isPremiumPayfee']);
			foreach ($hello as $key => $value) {
				$orderinfo['isPremiumPayfee'.($key+1)] = $value;
				if($orderinfo['isPremiumPayfee'.($key+1)] == 1) {
					$orderinfo['isPremiumPayfee'.($key+1)] = '是';
				}
									
			}

			unset($orderinfo['isPremiumPayfee']) ;

			$hello = explode(',',$orderinfo['PremiumPayfee']);
			foreach ($hello as $key => $value) {
				$orderinfo['PremiumPayfee'.($key+1)] = $value;
					if($orderinfo['PremiumPayfee'.($key+1)] == 0 and $orderinfo['PremiumPayfee'.($key+1)] != ''){
					$orderinfo['PremiumPayfee'.($key+1)]= '1-3月';
				}elseif ($orderinfo['PremiumPayfee'.($key+1)]== 1 ) {
					$orderinfo['PremiumPayfee'.($key+1)]= '3-6月';
				}elseif ($orderinfo['PremiumPayfee'.($key+1)]== 2 ) {
					$orderinfo['PremiumPayfee'.($key+1)]= '6-9月';
				}elseif ($orderinfo['PremiumPayfee'.($key+1)]== 3 ) {
					$orderinfo['PremiumPayfee'.($key+1)]= '9-12月';
				}elseif ($orderinfo['PremiumPayfee'.($key+1)]== 4 ) {
					$orderinfo['PremiumPayfee'.($key+1)]= '一年以上';
				}							
			}
			unset($orderinfo['PremiumPayfee']) ;

			$hello = explode(',',$orderinfo['carBrand']);
			foreach ($hello as $key => $value) {
				$orderinfo['carBrand'.($key+1)] = $value;
									
			}
			unset($orderinfo['carBrand']) ;

			$hello = explode(',',$orderinfo['CarBillPrice']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarBillPrice'.($key+1)] = $value;
									
			}
			unset($orderinfo['CarBillPrice']) ;

			$hello = explode(',',$orderinfo['CarYears']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarYears'.($key+1)] = $value;
									
			}
			unset($orderinfo['CarYears']) ;

			$hello = explode(',',$orderinfo['BuyCarType']);
			foreach ($hello as $key => $value) {
				$orderinfo['BuyCarType'.($key+1)] = $value;
				if($orderinfo['BuyCarType'.($key+1)] == 1){
					$orderinfo['BuyCarType'.($key+1)]= '全款';
				}elseif ($orderinfo['BuyCarType'.($key+1)] ==2) {
					$orderinfo['BuyCarType'.($key+1)]= '按揭';
				}			
									
			}
			unset($orderinfo['BuyCarType']) ;

			$hello = explode(',',$orderinfo['CarFirstPay']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarFirstPay'.($key+1)] = $value;
									
			}
			unset($orderinfo['CarFirstPay']) ;

			$hello = explode(',',$orderinfo['CarMonthPay']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarMonthPay'.($key+1)] = $value;
									
			}
			unset($orderinfo['CarMonthPay']) ;
			
			$hello = explode(',',$orderinfo['CarPayTimes']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarPayTimes'.($key+1)] = $value;
					if($orderinfo['CarPayTimes'.($key+1)] == 0 and $orderinfo['CarPayTimes'.($key+1)] != ''){
					$orderinfo['CarPayTimes'.($key+1)]= '1-3月';
				}elseif ($orderinfo['CarPayTimes'.($key+1)]== 1 ) {
					$orderinfo['CarPayTimes'.($key+1)]= '4-6月';
				}elseif ($orderinfo['CarPayTimes'.($key+1)]== 2 ) {
					$orderinfo['CarPayTimes'.($key+1)]= '6-11月';
				}elseif ($orderinfo['CarPayTimes'.($key+1)]== 3 ) {
					$orderinfo['CarPayTimes'.($key+1)]= '1-2年';
				}elseif ($orderinfo['CarPayTimes'.($key+1)]== 3 ) {
					$orderinfo['CarPayTimes'.($key+1)]= '3年以上';
				}						
			}
			unset($orderinfo['CarPayTimes']) ;

			$hello = explode(',',$orderinfo['isCarSupply']);
			foreach ($hello as $key => $value) {
				$orderinfo['isCarSupply'.($key+1)] = $value;
						if($orderinfo['isCarSupply'.($key+1)] == 1){
					$orderinfo['isCarSupply'.($key+1)]= '是';
				}elseif ($orderinfo['isCarSupply'.($key+1)] ) {
					$orderinfo['isCarSupply'.($key+1)]= '否';
				}			
			}
			unset($orderinfo['isCarSupply']) ;


			$hello = explode(',',$orderinfo['CarSupplyTime']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarSupplyTime'.($key+1)] = $value;
					if($orderinfo['CarSupplyTime'.($key+1)] == 0 and $orderinfo['CarSupplyTime'.($key+1)] != ''){
					$orderinfo['CarSupplyTime'.($key+1)]= '1-3月';
				}elseif ($orderinfo['CarSupplyTime'.($key+1)]== 1 ) {
					$orderinfo['CarSupplyTime'.($key+1)]= '3-6月';
				}elseif ($orderinfo['CarSupplyTime'.($key+1)]== 2 ) {
					$orderinfo['CarSupplyTime'.($key+1)]= '6-9月';
				}elseif ($orderinfo['CarSupplyTime'.($key+1)]== 3 ) {
					$orderinfo['CarSupplyTime'.($key+1)]= '9-12月';
				}elseif ($orderinfo['CarSupplyTime'.($key+1)]== 3 ) {
					$orderinfo['CarSupplyTime'.($key+1)]= '一年以上';
				}						
			}
			unset($orderinfo['CarSupplyTime']) ; 

			$hello = explode(',',$orderinfo['carWhichBank']);
			foreach ($hello as $key => $value) {
				$orderinfo['carWhichBank'.($key+1)] = $value;
									
			}
			unset($orderinfo['carWhichBank']) ;


			$hello = explode(',',$orderinfo['isCarInsurance']);
			foreach ($hello as $key => $value) {
				$orderinfo['isCarInsurance'.($key+1)] = $value;
						if($orderinfo['isCarInsurance'.($key+1)] == 1){
					$orderinfo['isCarInsurance'.($key+1)]= '有';
				}elseif ($orderinfo['isCarInsurance'.($key+1)] ) {
					$orderinfo['isCarInsurance'.($key+1)]= '没有';
				}			
			}
			unset($orderinfo['isCarInsurance']) ;


			$hello = explode(',',$orderinfo['carInsuranceCompany']);
			foreach ($hello as $key => $value) {
				$orderinfo['carInsuranceCompany'.($key+1)] = $value;
									
			}
			unset($orderinfo['carInsuranceCompany']) ;

			$hello = explode(',',$orderinfo['CarInsuranceCost']);
			foreach ($hello as $key => $value) {
				$orderinfo['CarInsuranceCost'.($key+1)] = $value;
									
			}
			unset($orderinfo['CarInsuranceCost']) ;

			$hello = explode(',',$orderinfo['houseType']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseType'.($key+1)] = $value;
					if($orderinfo['houseType'.($key+1)] == 1){
					$orderinfo['houseType'.($key+1)]= '商品房';
				}elseif ($orderinfo['houseType'.($key+1)]== 2 ) {
					$orderinfo['houseType'.($key+1)]= '自建房';
				}elseif ($orderinfo['houseType'.($key+1)]== 3 ) {
					$orderinfo['houseType'.($key+1)]= '其他';
				}				
			}
			unset($orderinfo['houseType']) ;

			$hello = explode(',',$orderinfo['houseAddress']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseAddress'.($key+1)] = $value;
									
			}
			unset($orderinfo['houseAddress']) ;

			$hello = explode(',',$orderinfo['houseSize']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseSize'.($key+1)] = $value;
									
			}
			unset($orderinfo['houseSize']) ;

			$hello = explode(',',$orderinfo['houseCost']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseCost'.($key+1)] = $value;
									
			}
			unset($orderinfo['houseCost']) ;

			$hello = explode(',',$orderinfo['houseByType']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseByType'.($key+1)] = $value;
						if($orderinfo['houseByType'.($key+1)] == 1){
					$orderinfo['houseByType'.($key+1)]= '全款';
				}elseif ($orderinfo['houseByType'.($key+1)] ==2) {
					$orderinfo['houseByType'.($key+1)]= '按揭';
				}			
			}
			unset($orderinfo['houseByType']) ;

			$hello = explode(',',$orderinfo['houseDegree']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseDegree'.($key+1)] = $value;
					if($orderinfo['houseDegree'.($key+1)] == 0 and $orderinfo['houseDegree'.($key+1)] != ''){
					$orderinfo['houseDegree'.($key+1)]= '1年以下';
				}elseif ($orderinfo['houseDegree'.($key+1)]== 1 ) {
					$orderinfo['houseDegree'.($key+1)]= '1-5年';
				}elseif ($orderinfo['houseDegree'.($key+1)]== 2 ) {
					$orderinfo['houseDegree'.($key+1)]= '5-10年';
				}elseif ($orderinfo['houseDegree'.($key+1)]== 3 ) {
					$orderinfo['houseDegree'.($key+1)]= '10-15年';
				}elseif ($orderinfo['houseDegree'.($key+1)]== 4 ) {
					$orderinfo['houseDegree'.($key+1)]= '15-20年';
				}elseif ($orderinfo['houseDegree'.($key+1)]== 5 ) {
					$orderinfo['houseDegree'.($key+1)]= '20年以上';
				}							
			}
			unset($orderinfo['houseDegree']) ;

			$hello = explode(',',$orderinfo['houseFirstPay']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseFirstPay'.($key+1)] = $value;
									
			}
			unset($orderinfo['houseFirstPay']) ;

			$hello = explode(',',$orderinfo['HouseMonthPay']);
			foreach ($hello as $key => $value) {
				$orderinfo['HouseMonthPay'.($key+1)] = $value;
									
			}
			unset($orderinfo['HouseMonthPay']) ;

			$hello = explode(',',$orderinfo['HousePayTimes']);
			foreach ($hello as $key => $value) {
				$orderinfo['HousePayTimes'.($key+1)] = $value;
					if($orderinfo['HousePayTimes'.($key+1)] == 0 and $orderinfo['HousePayTimes'.($key+1)] != ''){
					$orderinfo['HousePayTimes'.($key+1)]= '1-3月';
				}elseif ($orderinfo['HousePayTimes'.($key+1)]== 1 ) {
					$orderinfo['HousePayTimes'.($key+1)]= '3-6月';
				}elseif ($orderinfo['HousePayTimes'.($key+1)]== 2 ) {
					$orderinfo['HousePayTimes'.($key+1)]= '6-11月';
				}elseif ($orderinfo['HousePayTimes'.($key+1)]== 3 ) {
					$orderinfo['HousePayTimes'.($key+1)]= '1-2年';
				}elseif ($orderinfo['HousePayTimes'.($key+1)]== 4 ) {
					$orderinfo['HousePayTimes'.($key+1)]= '2-3年';
				}elseif ($orderinfo['HousePayTimes'.($key+1)]== 5 ) {
					$orderinfo['HousePayTimes'.($key+1)]= '3-4年';
				}elseif ($orderinfo['HousePayTimes'.($key+1)]== 6 ) {
					$orderinfo['HousePayTimes'.($key+1)]= '5年以上';
				}							
			}
			unset($orderinfo['HousePayTimes']) ;

			$hello = explode(',',$orderinfo['HouseWhichBank']);
			foreach ($hello as $key => $value) {
				$orderinfo['HouseWhichBank'.($key+1)] = $value;
									
			}
			unset($orderinfo['HouseWhichBank']) ;

			$hello = explode(',',$orderinfo['HouseLoanWho']);
			foreach ($hello as $key => $value) {
				$orderinfo['HouseLoanWho'.($key+1)] = $value;
					if($orderinfo['HouseLoanWho'.($key+1)] == 0 and $orderinfo['HouseLoanWho'.($key+1)] != ''){
					$orderinfo['HouseLoanWho'.($key+1)]= '本人';
				}elseif ($orderinfo['HouseLoanWho'.($key+1)]== 1 ) {
					$orderinfo['HouseLoanWho'.($key+1)]= '配偶';
				}elseif ($orderinfo['HouseLoanWho'.($key+1)]== 2 ) {
					$orderinfo['HouseLoanWho'.($key+1)]= '爸爸';
				}elseif ($orderinfo['HouseLoanWho'.($key+1)]== 3 ) {
					$orderinfo['HouseLoanWho'.($key+1)]= '妈妈';
				}elseif ($orderinfo['HouseLoanWho'.($key+1)]== 4 ) {
					$orderinfo['HouseLoanWho'.($key+1)]= '其他';
				}						
			}
			unset($orderinfo['HouseLoanWho']) ;//isHouseSupply


			$hello = explode(',',$orderinfo['isHouseSupply']);
			foreach ($hello as $key => $value) {
				$orderinfo['isHouseSupply'.($key+1)] = $value;
						if($orderinfo['isHouseSupply'.($key+1)] == 1){
					$orderinfo['isHouseSupply'.($key+1)]= '是';
				}elseif ($orderinfo['isHouseSupply'.($key+1)] ) {
					$orderinfo['isHouseSupply'.($key+1)]= '否';
				}			
			}
			unset($orderinfo['isHouseSupply']) ;

			$hello = explode(',',$orderinfo['HouseSupplyTime']);
			foreach ($hello as $key => $value) {
				
				$orderinfo['HouseSupplyTime'.($key+1)] = $value;
					if($orderinfo['HouseSupplyTime'.($key+1)] == 0 and $orderinfo['HouseSupplyTime'.($key+1)] !=''){
					$orderinfo['HouseSupplyTime'.($key+1)]= '1-3月';
				}elseif ($orderinfo['HouseSupplyTime'.($key+1)]== 1 ) {
					$orderinfo['HouseSupplyTime'.($key+1)]= '3-6月';
				}elseif ($orderinfo['HouseSupplyTime'.($key+1)]== 2 ) {
					$orderinfo['HouseSupplyTime'.($key+1)]= '6-9月';
				}elseif ($orderinfo['HouseSupplyTime'.($key+1)]== 3 ) {
					$orderinfo['HouseSupplyTime'.($key+1)]= '9-12月';
				}elseif ($orderinfo['HouseSupplyTime'.($key+1)]== 4 ) {
					$orderinfo['HouseSupplyTime'.($key+1)]= '一年以上';
				}						
			}
			// var_dump($orderinfo['HouseSupplyTime4']);die();
			unset($orderinfo['HouseSupplyTime']) ;

			$hello = explode(',',$orderinfo['houseContract']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseContract'.($key+1)] = $value;
					if($orderinfo['houseContract'.($key+1)] == 1){
					$orderinfo['houseContract'.($key+1)]= '房产证';
				}elseif ($orderinfo['houseContract'.($key+1)]== 2 ) {
					$orderinfo['houseContract'.($key+1)]= '购房合同';
				}elseif ($orderinfo['houseContract'.($key+1)]== 3 ) {
					$orderinfo['houseContract'.($key+1)]= '集体土地证';
				}elseif ($orderinfo['houseContract'.($key+1)]== 4 ) {
					$orderinfo['houseContract'.($key+1)]= '其他';
				}						
			}
			unset($orderinfo['houseContract']) ;

			$hello = explode(',',$orderinfo['houseBelong']);
			foreach ($hello as $key => $value) {
				$orderinfo['houseBelong'.($key+1)] = $value;
					if($orderinfo['houseBelong'.($key+1)] == 1){
					$orderinfo['houseBelong'.($key+1)]= '夫妻共有';
				}elseif ($orderinfo['houseBelong'.($key+1)]== 2 ) {
					$orderinfo['houseBelong'.($key+1)]= '与父母共有';
				}elseif ($orderinfo['houseBelong'.($key+1)]== 3 ) {
					$orderinfo['houseBelong'.($key+1)]= '与子女共有';
				}elseif ($orderinfo['houseBelong'.($key+1)]== 4 ) {
					$orderinfo['houseBelong'.($key+1)]= '个人';
				}						
			}
			unset($orderinfo['houseBelong']) ;

			$hello = explode(',',$orderinfo['HandleLoans']);
			foreach ($hello as $key => $value) {
				$orderinfo['HandleLoans'.($key+1)] = $value;
					if($orderinfo['HandleLoans'.($key+1)] == 0 and $orderinfo['HandleLoans'.($key+1)] != ''){
					$orderinfo['HandleLoans'.($key+1)]= '房产';
				}elseif ($orderinfo['HandleLoans'.($key+1)]== 1 ) {
					$orderinfo['HandleLoans'.($key+1)]= '保单';
				}elseif ($orderinfo['HandleLoans'.($key+1)]== 2 ) {
					$orderinfo['HandleLoans'.($key+1)]= '营业执照';
				}elseif ($orderinfo['HandleLoans'.($key+1)]== 3 ) {
					$orderinfo['HandleLoans'.($key+1)]= '车';
				}elseif ($orderinfo['HandleLoans'.($key+1)]== 4 ) {
					$orderinfo['HandleLoans'.($key+1)]= '公积金';
				}elseif ($orderinfo['HandleLoans'.($key+1)]== 5 ) {
					$orderinfo['HandleLoans'.($key+1)]= '其他';
				}						
			}
			unset($orderinfo['HandleLoans']) ;

			$hello = explode(',',$orderinfo['LoanMethod']);
			foreach ($hello as $key => $value) {
				$orderinfo['LoanMethod'.($key+1)] = $value;
					if($orderinfo['LoanMethod'.($key+1)] == 1){
					$orderinfo['LoanMethod'.($key+1)]= '抵押贷';
				}elseif ($orderinfo['LoanMethod'.($key+1)]== 2 ) {
					$orderinfo['LoanMethod'.($key+1)]= '信用贷';
				}elseif ($orderinfo['LoanMethod'.($key+1)]== 3 ) {
					$orderinfo['LoanMethod'.($key+1)]= '其他';
				}						
			}
			unset($orderinfo['LoanMethod']) ;

			$hello = explode(',',$orderinfo['LoanWhere']);
			foreach ($hello as $key => $value) {
				$orderinfo['LoanWhere'.($key+1)] = $value;
									
			}
			unset($orderinfo['LoanWhere']) ;

			$hello = explode(',',$orderinfo['LoansCost']);
			foreach ($hello as $key => $value) {
				$orderinfo['LoansCost'.($key+1)] = $value;
									
			}
			unset($orderinfo['LoansCost']) ;

			$hello = explode(',',$orderinfo['LoansDate']);
			foreach ($hello as $key => $value) {
				$orderinfo['LoansDate'.($key+1)] = $value;
									
			}
			unset($orderinfo['LoansDate']) ;

			$hello = explode(',',$orderinfo['LoansRepayMonth']);
			foreach ($hello as $key => $value) {
				$orderinfo['LoansRepayMonth'.($key+1)] = $value;
									
			}
			unset($orderinfo['LoansRepayMonth']) ;

			$hello = explode(',',$orderinfo['isLoanOnTime']);
			foreach ($hello as $key => $value) {
				$orderinfo['isLoanOnTime'.($key+1)] = $value;
					if($orderinfo['isLoanOnTime'.($key+1)] == 0 and $orderinfo['isLoanOnTime'.($key+1)] != ''){
					$orderinfo['isLoanOnTime'.($key+1)]= '正常';
				}elseif ($orderinfo['isLoanOnTime'.($key+1)]== 1 ) {
					$orderinfo['isLoanOnTime'.($key+1)]= '偶尔逾期';
				}elseif ($orderinfo['isLoanOnTime'.($key+1)]== 2 ) {
					$orderinfo['isLoanOnTime'.($key+1)]= '经常逾期';
				}					
			}
			unset($orderinfo['isLoanOnTime']) ;

			// $hello = explode(',',$orderinfo['isCheckCredit']);
			// foreach ($hello as $key => $value) {
			// 	$orderinfo['isCheckCredit'.($key+1)] = $value;
			// 		if($orderinfo['isCheckCredit'.($key+1)] == 1){
			// 		$orderinfo['isCheckCredit'.($key+1)]= '是';
			// 	}elseif ($orderinfo['isCheckCredit'.($key+1)] ) {
			// 		$orderinfo['isCheckCredit'.($key+1)]= '否';
			// 	}							
			// }
			// unset($orderinfo['isCheckCredit']) ;

			// $hello = explode(',',$orderinfo['CheckCreditMonth']);
			// foreach ($hello as $key => $value) {
			// 	$orderinfo['CheckCreditMonth'.($key+1)] = $value -1;
									
			// }
			// unset($orderinfo['CheckCreditMonth']) ;

			$hello = explode(',',$orderinfo['WhereCheckCreditMonth']);
			foreach ($hello as $key => $value) {
				$orderinfo['WhereCheckCreditMonth'.($key+1)] = $value;
									
			}
			unset($orderinfo['WhereCheckCreditMonth']) ;

			

			$hello = explode(',',$orderinfo['WhereCheckCreditYears']);
			foreach ($hello as $key => $value) {
				$orderinfo['WhereCheckCreditYears'.($key+1)] = $value;
									
			}
			
			unset($orderinfo['WhereCheckCreditYears']) ;
			
			//var_dump($orderinfo);die();
			$this->assign('orderinfo',$orderinfo);
			return $this->fetch();
		}else {
			$this->error('');
		}

	}
	//删除订单
	public function orderDelete(){

		$json = $GLOBALS['HTTP_RAW_POST_DATA'];
		$data = json_decode($json,true);
		$dataId = $data["id"];
		
		$order = db("order");
		if(is_array($dataId)){
			$c = count($dataId);
			$i = 0;
			
			foreach ($dataId as $key => $value) {
				
					$result = $order->where("id = $value")->update(['state' => '1']);	
						//判断是否全部删除成功
						if($result){
							$i = $i+1;
						}
						
			}
			if($result){
				echo 1;
			}
		}else{		
			$result = $order->where("id = $dataId")->update(['state' => '1']);
				// 成功
				if($result){
				echo 1;
			}
		}
	}
	//添加订单
	public function orderAdd(){
				
	}
	//资格认证
	public function authentication(){
		if(request()->isPost()){
		
			$data = input('post.order_sn');
			$Qualifications = input('post.Qualifications');
			if($Qualifications == 'confirm'){
				$arr = array('aptitude' => 1 ,'order_status'=>1);
			}elseif($Qualifications == 'insufficient'){
				$arr = array('aptitude' => 2 ,'order_status'=>2);
			}
			
			$order = db('order')->where("order_sn = '{$data}'") -> update($arr);
	
			$this->success('操作成功', 'orderList','',2);
	
		}		
	}

	//查看详情页面
	public function ss(){
		$this->success('新增成功', 'ss','',2);
		
	}

	//产品详情，用于订单后的各种操作
	public function orderGoodsinfo(){
		
		if(request()->isGet()){
			$arr = input('get.');

			$order = db('order');
			$arrs = $order ->where("order_sn = '{$arr['order_sn']}'")->find();
			if($arrs['sex']== 1){
				$name = mb_substr($arrs['userName'],0,1,'utf-8').'先生';
					$scheme = $name."贷款方案 : 约".$arrs['needToLoanMoney']."万";
			}elseif($arrs['sex']== 2){
				$name = mb_substr($arrs['userName'],0,1,'utf-8').'小姐';
					$scheme = $name."贷款方案 : 约".$arrs['needToLoanMoney']."万";
			}else{
			$scheme = $arrs['userName']."贷款方案 : 约".$arrs['needToLoanMoney']."万";
		}
			$this ->assign(['scheme' =>$scheme,
							'order_sn'=>$arr['order_sn']

		]);
			return $this->fetch();
		} 
			

			if(request()->isPost()){
				$where = $_POST;
				$goods = db('goods');
				$sql = "SELECT * FROM snake_goods WHERE {$where}  ";

			}	

			

	}
	function getTrees($data, $pId)
		{
		$tree = '';
		foreach($data as $k => $v)
		{
		  if($v['parent_id'] == $pId)
		  {        //父亲找到儿子
		   $v['parent_id'] = $this ->getTrees($data, $v['id']);
		   $tree[] = $v;
		   //unset($data[$k]);
		  }
		}
		return $tree;
		}

			public function ajaxCatinfo(){
			$fuzzy = db('select_cat');
				$arr = $fuzzy ->where("parent_id = 0")->select();
				if(request()->isAjax()){

					if($_POST !=null){

						$arr = $fuzzy ->where("parent_id = {$_POST['id']}")->select();
					
						return json($arr);
					
				}
				
				return json($arr);
				}
	}
	
	public function ajaxGoodsinfo(){

			if(request()->isAjax()){
			// $goods = db('goods');	
			// $goodsinfo = $goods -> select();
			// $post = input('post');
			// $pageNo = isset($post['page'])?$post['page']:'';
			// if($pageNo == ''){
			// 	$pageNo = 1;
			// }
			// $pagesize =15;
			// $page = ($pageNo-1)*$pagesize;
			// $where = 1;
			// //收到客户端{pageNo:1,pagesize:10} pagesize默认为15
			// $sql = "SELECT * FROM snake_goods WHERE{$where} limit $page, $pagesize";
			// $goodsinfo = $goods->query($sql);


			$post = input('get.');

			$whereor = "goods_type = 2 ";
			if (@$post['id']) {
				$id=$post['id'];
				$whereor="goods_type = 2 and (stair=$id or second_level=$id or three_level=$id) ";
			}
			if (@$post['goodsName']) {
				$name=$post['goodsName'];//'name','like','%thinkphp'
				$whereor="goods_type = 2 and name like '%{$name}%'";
			}

			//不知为毛不行
			/*$whereor = [
				['stair','=',$id],
				['second_level','=',$id],
				['three_level','=',$id],
			];*/

			//var_dump($whereor);
			//收到客户端{pageNo:1,pagesize:10} pagesize默认为15


			$goodsinfo = db('goods') ->where($whereor)->select();
			//echo db('goods')->getLastSql();
			return json($goodsinfo);

			
			}
	}
	
	public function thunderTest(){
		if(request()->isAjax()){
			//$order = db('rapidorder');
			//$arr = $order ->alias('o')->rightJoin('user u','o.salemanid = u.id')->where('state = 0 ') ->order('o.id desc')->select();
			$sql = "SELECT * FROM  snake_rapidorder as o left join  snake_user as u on  o.salemanid=u.id where o.state = 0 order by o.ids desc";
			$arr = db("order") ->query($sql);
			foreach ($arr as $key => $value) {
				if($value['fastJob'] ==1 ){
					$arr[$key]['fastJob'] = '做生意';
				}elseif ($value['fastJob'] ==2) {
					$arr[$key]['fastJob'] = '上班族';
				}elseif ($value['fastJob'] ==3) {
					$arr[$key]['fastJob'] = '优良职业';
				}
			}
			return json($arr);
		}
		return $this->fetch();
	}
	public function thunderTestinfo(){
			if(request()->isGet()){
			$data = input('get.id');
			// 产品详情
			$orderinfo = db('rapidorder')->where("ids = {$data} ")->find();
			if($orderinfo['fastJob'] ==1 ){
					$orderinfo['fastJob'] = '做生意';
				}elseif ($orderinfo['fastJob'] ==2) {
					$orderinfo['fastJob'] = '上班族';
				}elseif ($orderinfo['fastJob'] ==3) {
					$orderinfo['fastJob'] = '优良职业';
				}
				if($orderinfo['isHouse']== 1){$orderinfo['isHouse'] = '是';}
				if($orderinfo['isInsurance']== 1){$orderinfo['isInsurance'] = '是';}
				if($orderinfo['isCar']== 1){$orderinfo['isCar'] = '是';}
				if($orderinfo['isFund']== 1){$orderinfo['isFund'] = '是';}
				
				$this->assign('thundertestinfo',$orderinfo);
			return $this->fetch();
			}
	}
	public function thunderTestDelete(){

		$json = $GLOBALS['HTTP_RAW_POST_DATA'];
		$data = json_decode($json,true);
		$dataId = $data["id"];
		
		$order = db("rapidorder");
		if(is_array($dataId)){
			$c = count($dataId);
			$i = 0;
			
			foreach ($dataId as $key => $value) {
				
					$result = $order->where("ids = $value")->delete();	
						//判断是否全部删除成功
						if($result){
							$i = $i+1;
						}
						
			}
			if($result){
				echo 1;
			}
		}else{		
			$result = $order->where("ids = $dataId")->delete();
				// 成功
				if($result){
				echo 1;
			}
		}
	}
	//跳转方案页面
	public function schemeinfo(){

		return $this->fetch('orderfinal');
	}
	//方案表
	public function ajaxZizhi(){
		if(request()->isAjax()){
			
			$scheme = db('scheme');

			$goods = db('goods');
			$post = input('post.');
			
			if($post['versions'] == ""){
					$versions =1;
			}else{
				$versions =$post['versions'] +1;
			}

			//$versions = isset($post['versions'])?$post['versions']+1:1; //版本好
			//var_dump($versions);die();
			$post['hlightid'] = isset($post['hlightid'])?$post['hlightid']:'';
			if($post['hlightid'] != ''){
			$hlightid = explode('/',$post['hlightid']); 
		}
			$arr = json_decode($post['id'],true);
			
			
			foreach ($arr as $key => $value) {
				// if($value['stair'] == 1){
				// 	$arrs['patterns_lending'] ='无抵押信用贷';
				// }else{
				// 	$arrs['patterns_lending'] ='无抵押信用贷';
				// }
			
				if($value['three_level'] == 111 or $value['three_level'] ==127 or $value['three_level'] ==119){
					$arrs['type'] ='1';//保单
					$arrs['patterns_lending'] ='无抵押信用贷';
					$arrs['remark'] ='一切方案尽以征信、保单网核过关为准';
				}elseif($value['second_level'] == 95 or $value['second_level'] == 93 or $value['second_level'] == 97 ){
					$arrs['type'] ='3';//抵押
					$arrs['patterns_lending'] ='抵押贷';
					$arrs['mode_repayment'] ='等额本息还款';
						$arrs['remark'] ='一切方案尽以征信过关为准';
				}else{
					$arrs['patterns_lending'] ='无抵押信用贷';
					$arrs['remark'] ='一切方案尽以征信过关为准';
					$arrs['type'] ='2';//房
				}

				$arrs['goods_id'] = $value['id'];
				$arrs['order_id'] = $post['order_sn'];
				$goodsarr = $goods -> where("id = '{$value['id']}'") ->find();
			
				$arrs['platform_fee'] = $goodsarr['platform_fee'];//根据产品内容插入
				$arrs['datum'] = $goodsarr['date'];//根据产品内容插入
				$arrs['time'] = $goodsarr['time'];
				$arrs['refund'] = 0;
				$arrs['name'] = $value['name'];
				$arrs['scheme_name'] = $post['scheme'];
				$arrs['versions'] = $versions;//版本
				$arrs['interest'] =$goodsarr['interest'];//根据产品内容插入
				$arrs['credit_investigation'] =$goodsarr['credit_investigation'];//根据产品内容插入
				$arrs['credit'] =$goodsarr['credit'];//根据产品内容插入
				$arrs['Comprehensive'] = round(($goodsarr['platform_fee']/12/3)+$goodsarr['interest'], 2);//综合月利息
				$arrs['date'] = date('Y-m-d H:m',time());
				$arrs['highlight'] = 0;
				$arrs['sort'] = $key+1;
				if($post['hlightid'] != ''){
				foreach ($hlightid as $key => $value) {
					if($arrs['goods_id'] == $value){
						$arrs['highlight'] = 1;
					}
				}
				
				
				}
				// $arrs['cause'] = $post['cause'];
				
				$scheme ->insert($arrs);
			}
			if($arrs['type'] != 3){
				if($arrs['type'] = 1){
					$arrs['type'] = 4;
				}elseif ($arrs['type'] = 2) {
					$arrs['type'] = 5;
				}
			//根据开始表生成浓缩表 concentration 这个字段判断方案版本 concentration= 1
			$arr  = array('name' => 'XK',
					'time' => '5-7天',
					'mode_repayment' => '等本等息还款',
					'patterns_lending' => '无抵押信用贷',
					'concentration' => 1,
					'scheme_name' => $post['scheme'],
					'order_id' => $post['order_sn'],
					'versions' => $versions,//版本
				    'date'=> date('Y-m-d H:m',time()),
					'type' => $arrs['type']

			 );
			$a = $scheme ->where("concentration = 1 and order_id = '{$post['order_sn']}'and versions = '{$versions}'")->find();
						
if($a == null){
			$scheme ->insert($arr);
}
		}
			$order = db("order");//更改订单状态为已经挑选方案
			$state = array( "order_status" => 3);
			$order ->where("order_sn = '{$post['order_sn']}'")->update($state);
			return json($post['order_sn']);
		}

	}
	//生成方案表
	public function ajaxScme(){
			
			$sn_arr = input('post.');

			$order_sn = $sn_arr['order_sn'];
			$scheme = db('scheme');
			$goods = db('goods');
			
			
			$group= $scheme ->where("order_id = '{$order_sn}' AND concentration = 0 ")->group('versions') ->select();

			$i = 1;

			foreach ($group as $key => $value) {

					$arr = $scheme ->where("order_id = '{$order_sn}' AND concentration = 0 and versions = '{$value['versions']}' ") ->order('sort')->select();
					$arrs= $scheme ->where("order_id = '{$order_sn}' AND concentration = 1 and versions = '{$value['versions']}' ")->order('sort')->select();
					
					$arrlist[$i] = $arr;
					$i=$i+1;
					if($arrs != null){

					
					$arrlist[$i] = $arrs;
					
					$i = $i+1;}
			}
			
			//var_dump($arrlist);die();
			// $arrlist['3'] = $arr;
			// $arrlist['3']['0']["name"] = '2222222222222';
			// $arrlist['3']['1']["name"] = '2222222222222';
			// $arrlist['3']['2']["name"] = '2222222222222';
			// $arrlist['4'] = $arrs;
			// $arrlist['4']['0']["name"] = '2222222222222';
			// // $arrs['1'] =$arr;
			// $arrs['2'] = $arr;
			// $arrs['2']['0']["order_id"] = '2222222222222';
			// $arrs['2']['1']["order_id"] = '2222222222222';
			// $arrs['2']['2']["order_id"] = '2222222222222';
			// $arrs['2']['3']["order_id"] = '2222222222222';
			
			 //var_dump($arrlist);die();
			return json($arrlist);
		
	}
	//更新方案
	public function ajaxUpdateSc(){
		if(request() ->isAjax()){
			$arrs = input('post.');

			
			$scheme = db('scheme');  
			   	$lists = $scheme ->where('id',$arrs['vid'])->find();
			if($lists['type'] == 3){
			   		$arr = array('loan_money'=>rtrim($arrs['Amountofloan'], "万")  ,
						'deadline'=> rtrim($arrs['Loanterm'], "年"),
						'name'=>  $arrs['Financialcode'],
					
						'time'=>  $arrs['Lendingtime'],
						'Comprehensive'=>  rtrim($arrs['Comprehensive'],"%"),
						'platform_fee'=>  rtrim($arrs['Disposable'],"%"),
						'interest'=>  rtrim($arrs['Later'],"%"),
						'mode_repayment'=>  $arrs['Repaymentmethod'],
						'refund'=> $arrs['Monthlyrepayment'],
						'cost'=>  $arrs['cost'],
						'remarks'=>  $arrs['remarks'],
						'channel' => $arrs['channel'],
						'costs' => $arrs['costs'],
						
						);
	 	}else{

			$arr = array('loan_money'=>rtrim($arrs['Amountofloan'], "万")  ,
						'deadline'=>rtrim($arrs['Loanterm'], "年")  ,
						// 'interest'=>substr($arrs['Later'] ,0,strlen($arrs['Later'])-1) ,
						// 'mode_repayment'=>$arrs['Repaymentmethod']
						
						);
		$p = 	rtrim($arrs['Amountofloan'], "万") ;//钱
		$p = $p*10000;
		$j =  rtrim($arrs['Loanterm'], "年") ;//年
		
		$list = $scheme -> where("id = '{$arrs['vid']}'") -> find();
		$c = $list['interest'];//后期还款
		$a = $list['platform_fee'];//平台费用
			$Comprehensive = round(($a/12/$j)+$c,2);					//综合月利息
			$refund	 = round(($p/(12*$j))+($p*$c*0.01),0);//每月还款
			$arr = array('loan_money'=>$p/10000,
						'deadline'=>$j,
						// 'interest'=>substr($arrs['Later'] ,0,strlen($arrs['Later'])-1) ,
						// 'mode_repayment'=>$arrs['Repaymentmethod']
						'Comprehensive' => $Comprehensive,
						'channel' => $arrs['channel'],
						'costs' => $arrs['costs'],
						'refund' => $refund
		);		
		}									
		$aa = $scheme -> where("id = '{$arrs['vid']}'") -> update($arr);
        	 $lists = $scheme -> where("id = '{$arrs['vid']}'") -> find();
        	 $versions = $lists['versions'] ;
        	 $order_sn = $lists['order_id'] ;
        	  $versions = $lists['versions'] ;
        	 $order_sn = $lists['order_id'] ;
        	  $lists = $scheme -> where("versions = '{$versions}' and order_id = '{$order_sn}' and concentration = 0 ") -> select();
        	  $p = 0; //总金额
        	  foreach ($lists as $key => $value) {
        	  	$p = $value['loan_money'] +$p;
        	  }

        	 $namearr = db('order') -> where('order_sn', $order_sn) ->find();
        	 $name = $namearr['userName'];
        	 if($namearr['sex']== 1){
				$names = mb_substr($name,0,1,'utf-8').'先生';
					 $dai = $names."贷款方案"." ：约".$p."万";
			}elseif($namearr['sex']== 2){
				$names = mb_substr($name,0,1,'utf-8').'小姐';
				 $dai = $names."贷款方案"." ：约".$p."万";
			}else{
		 		$dai = $name."贷款方案"." ：约".$p."万";
			}
        	 
        	 //$dai = $name."贷款方案"." ：约".$p."万";

        	 $arrayName = array('scheme_name' => $dai);
        	  $lists = $scheme -> where("versions = '{$versions}' and order_id = '{$order_sn}'  ") -> select();
        	 foreach ($lists as $key => $value) {
        	 	 $scheme -> where("id = '{$value['id']}'") -> update($arrayName);
        	 }
			if($aa){
				echo "success";
			}
        	}
        
		
	}
	//删除某些方案
	public function deleteScheme(){
		if(request() ->isAjax()){

			$arrs = input('post.');
			$scheme = db('scheme');
			
			 $lists = $scheme -> where("id = '{$arrs['id']}'") -> find();
			 $id = $scheme -> where("id = '{$arrs['id']}'") ->delete();
        	 $versions = $lists['versions'] ;
        	 $order_sn = $lists['order_id'] ;
        	  $versions = $lists['versions'] ;
        	 $order_sn = $lists['order_id'] ;
        	  $lists = $scheme -> where("versions = '{$versions}' and order_id = '{$order_sn}' and concentration = 0 ") -> select();
        	  $p = 0; //总金额
        	  foreach ($lists as $key => $value) {
        	  	$p = $value['loan_money'] +$p;
        	  }

        	 $namearr = db('order') -> where('order_sn', $order_sn) ->find();
        	 $name = $namearr['userName'];
        	 if($namearr['sex']== 1){
				$names = mb_substr($name,0,1,'utf-8').'先生';
					 $dai = $names."贷款方案"." ：约".$p."万";
			}elseif($namearr['sex']== 2){
				$names = mb_substr($name,0,1,'utf-8').'小姐';
				 $dai = $names."贷款方案"." ：约".$p."万";
			}else{
		 		$dai = $name."贷款方案"." ：约".$p."万";
			}
        	 
        	 //$dai = $name."贷款方案"." ：约".$p."万";

        	 $arrayName = array('scheme_name' => $dai);
        	  $lists = $scheme -> where("versions = '{$versions}' and order_id = '{$order_sn}'  ") -> select();
        	 foreach ($lists as $key => $value) {
        	 	 $scheme -> where("id = '{$value['id']}'") -> update($arrayName);
        	 }
			if($id){
				echo 1;
			}
		}
	}
	//返回弹框内容
	public function schemeContent(){
		if(request() ->isAjax()){
			$arrs = input('post.');
			$goods = db('goods');
			$arr = $goods -> where("id = '{$arrs['id']}'")  -> find();
			
			return json($arr['content']);
		}
	}


	public function insertScheme(){
	
		$scheme = db('scheme');
		$arrs = input('post.');

		$i=0;
		$k =0;
		foreach ($arrs['arr'] as $key => $value) {
			$k = $k+1;
			if($k<12){
				$arr[$i][$k] = $value;

			}else{
				$k = 0;
				$i= $i+1;
			}

		}
		foreach ($arr as $key => $value) {
			
			$arrayName = array(
				'name' =>$value['1'] ,
				'patterns_lending' =>$value['2'] ,
				'time' => rtrim($value['3'], '天') ,
				'loan_money' =>rtrim($value['4'], '万'),
				'deadline' =>rtrim($value['5'], '年'),
				'synthesize' =>substr($value['6'] ,0,strlen($value['6'] )-1) ,
				'platform_fee' =>substr($value['7'] ,0,strlen($value['7'] )-1) ,
				'interest' =>substr($value['8'] ,0,strlen($value['8'] )-1),
				'mode_repayment' =>$value['9'] ,
				'refund' =>$value['10'] ,


			 );
			

			$scheme ->where("id = '{$value['11']}'") ->update($arrayName);
		}
		$orderarr = $scheme ->where("id = '{$arrs['arr']['10']}'") ->find();
		
		$id = db('order')->where('order_sn',$orderarr['order_id']) ->update(['order_status' => 4]);

		return $orderarr['order_id'];
	}

	public function printScheme(){
		return $this ->fetch('finalprinting');
	}
	public function ajaxZizhi2(){
		if(request() ->isAjax()){
			$order_sn = input('post.');
			//$arr = $order_sn['order_sn'] -1;
			return json($order_sn['order_sn']);
		}
	}
	//我要加盟jdbc
	public function joinList(){
		if(request() ->isAjax()){
		$arr = db('joinus')->select();
		return json($arr);
		}
		return $this -> fetch('joinus');
	}
	public function joininfo(){
		if(request() ->isAjax()){
		$idarr = input('post.');
		$arr = db('joinus')->where('id',$idarr['id'])->find();
		return json($arr);
		}
	}

	public function joinDelete(){
		$json = $GLOBALS['HTTP_RAW_POST_DATA'];
		$data = json_decode($json,true);
		$dataId = $data["id"];
		
		$joinus = db('joinus');
		if(is_array($dataId)){
			$c = count($dataId);
			$i = 0;
			
			foreach ($dataId as $key => $value) {
				
					$result = $joinus->where("id = $value")->delete();	
						//判断是否全部删除成功
						if($result){
							$i = $i+1;
						}
						
			}
			if($result){
				echo 1;
			}
		}else{		
			$result = $joinus->where("id = $dataId")->delete();
				// 成功
				if($result){
				echo 1;
			}
		}
	}
	//为什么不挑选
	public function noSelect(){

		if(request() ->isAjax()){
			
			if($_POST['versions'] == ""){
					$versions =1;
			}else{
				$versions =$_POST['versions'] +1;
			}

		$order_sn = input('post.order_sn');

		 $data = db('goods')->alias('c')
		
        ->join('scheme g','c.id = g.goods_id','left')
        ->field('stair,three_level,second_level,c.id')
        ->where("g.order_id='{$order_sn}' and  g.versions = '{$versions}'")
        ->select();
       
        $wheres = '';
        foreach ($data as $key => $value) {
        	$a = "id != ". $value['id'];
        	if($wheres == ''){
        	$wheres = $a;
        }else{
        	$wheres = $wheres . " and " .$a;
        }
    }
    $stair = $data[0]['stair'];
    $three_level = $data[0]['three_level'];
    $second_level = $data[0]['second_level'];
    $wheres = "stair = $stair and three_level = $three_level and second_level = $second_level and ".$wheres;
      $s = db('goods') -> where($wheres) -> select();
        return json($s);
    }else{
    	return $this ->fetch('orderveto');
    }
	}

	//为什么不挑选的产品添加和显示
	public function highlight(){
			//$arr = input('post');
			$arr = json_decode($_POST['field'],true);
			$a =1;$i = 0;
			foreach ($arr as $key => $value) {
				
				if($a == 2){
					$a =1;
					$list[$i]['goods_id'] = $value; 
					$i = $i+1;
				}else{
					$a=$a+1;
					$list[$i]['highlight'] = $value;
				}

			}
			$i = count($list) -1;
			foreach ($list as $key => $value) {
				$list[$key]['order_sn'] = $list[$i]['highlight'];
			}
		
			unset($list[$i]);
			
			
			foreach ($list as $key => $value) {
				$no = 	db('no_selsct') ->insert($value);
			}

		return 1;
	}
	public function sort(){
		if(request()-> isAjax()){
			$scheme = db('scheme');
			$data = input('post.');
			$id = $data['goods'];
			
			$list = $scheme ->where('id',$id)->find();
			if( $list['sort'] !=0){
			$sort = $list['sort'] -1;
			$lists = $scheme ->where("concentration = 0 and versions = '{$data['versions']}' and order_id = '{$data['order_sn']}' and sort = '{$sort}' ")->find();
			$arrayName = array('sort' =>$list['sort']-1, );
			$arrayNames = array('sort' =>$lists['sort']+1, );
			
			$scheme ->where('id',$id)->update($arrayName);
			$scheme ->where('id',$lists['id'])->update($arrayNames);
			}echo 1;

		}
	}
	
	// }
	//合成浓缩表
	public function updateSynthesize(){
		$scheme = db('scheme');
		$data = $_POST;
		//第一步先保存编辑内容

		$arr =	$scheme ->where("concentration = 0 and versions = '{$data['versions']}' and order_id = '{$data['order_sn']}'")->order('sort') ->select();
		$datum ='';
		$i = count($arr);
		// foreach ($arr as $key => $value) {
		// 	$datum = $value['datum']."\n".$datum;
		// }
		foreach ($arr as $key => $value) {
			$datum = $arr[$i-1]['datum']."\n".$datum;
			$i = $i-1;
		}
		$remark =$arr['0']['remark'] ;
		$p = 0;//平台总费用
		$j = 0;//后期还贷利息每月金额总
		$a = 0;//每月还款钱
		
		$d = 0;//贷款总金额

		foreach ($arr as $key => $value) {

			$d = $value['loan_money']*10000+ $d ;	
			$p = ($value['loan_money']*10000)*($value['platform_fee']*0.01) + $p;
			$j = ($value['loan_money']*10000)*($value['interest']*0.01) + $j;
			$a = $value['refund']+ $a ;
		}
		$c = 0;
		$q = 0;//后期还贷利息金额
		@$platform_fee  = round($p/$d*100,2) ; //一次性前置利息/平台保险费
		@$interest  = round($j/$d*100,2) ;///后期还贷利息金额
		$refund = $a ;

		$Comprehensive = round(($platform_fee/12/$arr[0]['deadline']) + $interest,2);//综合月利息
		$list = array('platform_fee' => $platform_fee,
						'interest' => $interest,
						'refund' => $refund,
						'Comprehensive' => $Comprehensive,
						'remark' => $remark,
						'datum' => $datum, 
						'deadline' => $arr[0]['deadline'], 
						'loan_money' => $d/10000
		 );
		
		$scheme  ->where("concentration = 1 and versions = '{$data['versions']}' and order_id = '{$data['order_sn']}'") ->update($list);
		echo 1 ;
	}
	// //跳转页面打印
	public  function prints(){
		$scheme = db('scheme');
		$data = $_POST;
		$arr = $scheme ->where("order_id = '{$data['order_sn']}' AND concentration = '{$data['concentration']}' and versions = '{$data['versions']}'") ->order('sort') ->select();
			return json($arr);
		
	}
	public function updateSchemeSubordinate(){
		$scheme = db('scheme');
		
		$data = $_POST;
		$s = explode("\n",$data['ready']);
		$arr = $scheme ->where("order_id = '{$data['order_sn']}' AND concentration = 0 and versions = '{$data['versions']}'") ->order('sort') ->select();
	
		foreach ($arr as $key => $value) {
			$arrs = array('remark' => $data['ready1'],
						 'datum' => $s[$key],
				);

			$scheme ->where("id = '{$value['id']}'") ->update($arrs);
		}
		$list ='';
		
		if(count($s) != count($arr)){
			foreach ($s as $key => $value) {
				if(($key+1) >= count($arr)){
					if($list == ''){
					$list = $value;
				}else{
					$list = $list."\n".$value;
				}
				}
			}
			$arrs = array(
						 'datum' => $list,
				);
			$i = count($arr) -1;
			//var_dump($arr[$i]['id']);

			$scheme ->where("id = '{$arr[$i]['id']}'") ->update($arrs);
		}

		echo 1 ;
	}
	//跳转打印
	public function dayinprinting(){
		return $this ->fetch();
	} 

	//添加vip订单
	public function vipInsertOrder(){
		$order = db('order');
		$arr = input('post');
		$sn = date('Ymdhis') . str_pad(mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);

        $d = date("Y-m-d H:i:s",time());
      
		$arrayName = array('order_sn' =>$sn ,
						'time' => $d ,
						'vip_judgement' => 1 ,
						'vip_user' =>$_POST['user'] ,
						'userName' =>$_POST['ad_name'] ,
						'mobile' =>$_POST['phone'] ,
						'vip_userSituation' =>$_POST['userSituation'] ,
						'vip_Loan' =>$_POST['Loan'] ,
						'vip_CreditCard' =>$_POST['CreditCard'] ,
						'vip_Amountused' =>$_POST['Amountused'] ,
						'needToLoanMoney' =>$_POST['money'] ,
						'sex' =>$_POST['cat_sex'] ,
						'vip_amountonloan' =>$_POST['vip_amountonloan'] ,
						// 'needToLoanMoney' =>$_POST['needToLoanMoney'] ,
		 );
		$id = $order ->insert($arrayName);
		if ($id) {
			$this->success('添加成功', 'vipList','',2);
	 
		}

	}
	//获取业务员信息
	public function salesmanList(){
		$user = db('user');
		$arr = $user ->where('role_id',3) ->field('real_name')->select();
		return json($arr);
	}
	//vip订单号
	public function vipList(){
		$order = db('order');
		if(request() ->isAjax()){
			$arr = $order ->where("vip_judgement = 1 and state = 0 ")->order('id desc')->select();
			return json($arr);
		}
		$arr = $order ->where("vip_judgement = 1 ")->select();
		return $this -> fetch('ordervip');
	}
	//
	public function vipadd(){
		return $this -> fetch('vipadd');
	}
	public function ordervip(){
		$id = input('get.id');
		$order = db('order');
		$arr = $order ->where('id',$id) ->field('vip_user,userName,mobile,vip_userSituation,vip_Loan,vip_CreditCard,vip_Amountused,order_sn,order_status,needToLoanMoney,vip_amountonloan')->find();
		
		$this ->assign('arr',$arr);
		return $this -> fetch('vipsee');



	}
	//不挑选页面
	public function nolist(){
		$order_sn = input('post.order_sn');
	 	$data = db('no_selsct')->alias('c')
        ->join('goods g','c.goods_id = g.id','left')
        ->where("c.order_sn='{$order_sn}' ")
        ->select();

        return json($data);
	}
	//跳转
	public function orderwhy(){
		return $this -> fetch('orderwhy');
	}
	public function ceshi(){
		$code =  '马晓东';
            $mobile = 13632374351;
           
             $result = sendMsg2($mobile, $code);//业务通知
             var_dump($result);

	}
	public function updateSmMo(){
	$scheme = db('scheme');	
	$date = input('post.');
	//var_dump($date['versions']);
	$scheme_name = $date['money'];
	$arr =  array('scheme_name' => $scheme_name, );
	$scheme ->where("order_id = '{$date['order_id']}' and versions = '{$date['versions']}' and concentration = '{$date['concentration']}'") -> update($arr);
	//substr($date['versions'],);
	}

	public function daying(){
		$order_sn = input('post.order_sn');

		$arrayName = array('order_status' => 4, );
		$id = db('order') ->where('order_sn',$order_sn)->update($arrayName);
	}
	public function statusUpdate(){
		$arr = input('get.order_sn');
		$arrs = db('order') ->where('order_sn',$arr)->find();
		$order_status = $arrs['order_status'];
		$order_status = $order_status + 1 ;
		$arrayName = array('order_status' => $order_status, );
		$id = db('order') ->where('order_sn',$arr)->update($arrayName);
		if($id){
		$this->success('操作成功', 'orderList','',2);
		}

	}
	public function resultUpdate(){
			$order_sn = input('get.order_sn');
			$result = input('get.results');
			$arrayName = array('results' => $result,);
		$id = db('order') ->where('order_sn',$order_sn)->update($arrayName);
		if($id){
		$this->success('操作成功', 'orderList','',2);
		}
	}
}
	  